import { _decorator, Component, Node, tween, v3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('FightCover')
export class FightCover extends Component {

    @property(Node)
    coverUp:Node
    @property(Node)
    coverDown:Node
    @property(Node)
    one:Node
    @property(Node)
    two:Node
    @property(Node)
    three:Node
    @property(Node)
    fightStart:Node

    private speed:number = 0.2

    start() {

    }

    
    /**开屏动画 */
    async playCover(){
        await this.wait(0.2)
        let upPos = v3(0, -230, 0)
        let downPos = v3(0, 230, 0)
        
        let offset = v3(1,0.6,0).normalize()
        this.coverUp.position = upPos.clone().add(offset.clone().multiplyScalar(1200))
        this.coverDown.position = downPos.clone().subtract(offset.clone().multiplyScalar(1200))
        
        
        tween( this.coverUp)
        .to(this.speed, {position: upPos})
        .start()

        tween(this.coverDown)
        .to(this.speed, {position: downPos})
        .start()

        await this.wait(0.2)
       this.showNum(this.three)
        await this.wait(1)
        this.showNum(this.two)
        await this.wait(1)
        this.showNum(this.one)
        await this.wait(1)
        this.showNum(this.fightStart)
        await this.wait(1)
        this.fightStart.active = false

        let a = upPos.clone().subtract(offset.clone().multiplyScalar(1200))
        let b = downPos.clone().add(offset.clone().multiplyScalar(1200))

        tween( this.coverUp)
        .to(this.speed, {position: a})
        .start()

        tween(this.coverDown)
        .to(this.speed, {position: b})
        .start()
        await this.wait(0.5)
        
    }

    async showNum(node:Node){
        this.one.active = false
        this.two.active = false
        this.three.active = false

        node.active = true

        node.position = v3(0, 0, 0)
        node.scale = v3(2,2,2)
        tween(node)
        .to(0.2, {scale: v3(1,1,1)})
        .start()
    }

    wait(num:number){
        return new Promise((resolve) => {
            this.scheduleOnce(() => {
                resolve(1)
            },num)
        })
    }
}


